import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;
    public MinStack() {
        this.stack = new Stack<>();
        this.minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minStack.isEmpty()){
           minStack.push(val);
       }else {
            if(val <= minStack.peek()){
                minStack.push(val);
            }
        }
    }

    public void pop() {
        if(!stack.isEmpty()) {
            stack.pop();
            if (stack.pop() == minStack.peek()) {
                minStack.pop();
            }
        }
    }

    //获取正常栈顶元素
    public int top() {
        if(stack.isEmpty()) {
            return -1;
        }
        return stack.peek();
    }

    //获取最小栈顶元素
    public int getMin() {
        if(minStack.isEmpty()) {
            return -1;
        }
        return minStack.peek();
    }
}
